package cn.qingyun.gis.modules.scenes.conver;

import com.alibaba.excel.converters.Converter;
import com.alibaba.excel.enums.CellDataTypeEnum;
import com.alibaba.excel.metadata.GlobalConfiguration;
import com.alibaba.excel.metadata.data.ReadCellData;
import com.alibaba.excel.metadata.data.WriteCellData;
import com.alibaba.excel.metadata.property.ExcelContentProperty;

public class BusinessStateConverter implements Converter<Integer> {

    @Override
    public Class supportJavaTypeKey() {
        return Integer.class;
    }

    @Override
    public CellDataTypeEnum supportExcelTypeKey() {
        return CellDataTypeEnum.STRING;
    }

    @Override
    public WriteCellData<String> convertToExcelData(Integer value, ExcelContentProperty contentProperty, GlobalConfiguration globalConfiguration) {
        if (value==null){
            return new WriteCellData<>("");
        }
        if (value==0){
            return new WriteCellData<>("正常营业");
        }else if (value==1){
            return new WriteCellData<>("装修中");
        }else if (value==2 ){
            return new WriteCellData<>("已倒闭");
        }
        return new WriteCellData<>("");
    }

    @Override
    public Integer convertToJavaData(ReadCellData<?> cellData, ExcelContentProperty contentProperty, GlobalConfiguration globalConfiguration) {
        String value = cellData.getStringValue();
        if (value==null){
            return null;
        }
        switch (value) {
            case "正常营业":
                return 0;
            case "装修中":
                return 1;
            case "已倒闭":
                return 2;
        }
        return null;
    }
}

